package com.niit.spark.rdd.test

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * Date:2025/5/9
 * Author：Ys
 * Description:
 */
object MapValuesExercise {
  def main(args: Array[String]): Unit = {
    val sparkConf = new
        SparkConf().setMaster("local[*]").setAppName("MapValuesExercise")
    val sc = new SparkContext(sparkConf)
    val productPricesRDD = sc.parallelize(Seq(("ProductA", 25.5), ("ProductB",
      75.8), ("ProductC", 120.0), ("ProductD", 45.2)))

    val resRdd: RDD[(String, String)] = productPricesRDD.mapValues(price => {
      if (price < 0) {
        "0-50区间"
      } else if (price < 100) {
        "50-100区间"
      } else {
        "100以上区间"
      }

    })

    resRdd.collect().foreach(println)


    sc.stop()
  }

}
